package com.demo.blog.pojo.response;

import com.demo.blog.common.enums.ResultCodeEnum;
import lombok.Data;

@Data
//统一返回的对象实体类
public class Result<T> {
    //状态码
    private int code;
    //错误信息
    private String errMsg;
    //数据
    private T data;

    //成功返回
    public static <T> Result<T> success(T data) {
        //创建一个Result对象
        Result result = new Result<>();
        //设置状态码
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        //设置数据
        result.setData(data);
        return result;
    }

    //失败返回
    public static <T> Result<T> fail(String errMsg) {
        Result result = new Result<>();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;
    }
}
